package lei;

/**
 * @className: Main3
 * @author: xl
 * @date: 2025/7/20 13:29
 * @Version: 1.0
 * @description:
 */

public class Main3<K, V> implements Name<K, V> {

    private K key;
    private V value;

    public Main3() {
    }

    public Main3(K key, V value) {
        this.key = key;
        this.value = value;
    }

    public void setKey(K key) {
        this.key = key;
    }

    public void setValue(V value) {
        this.value = value;
    }

    @Override
    public K getKey() {
        return null;
    }

    @Override
    public V getValue() {
        return null;
    }

    @Override
    public String toString() {
        return "Main3{" +
                "key=" + key +
                ", value=" + value +
                '}';
    }

    public static <K, V> Main3<K, V> of(K key, V value) {
        return new Main3<>(key, value);
    }

    public static void main(String[] args) {
        Main3<String, Integer> pair1 = new Main3<>("Age", 25);
        var pair2 = new Main3<>("Age", 25);
        System.out.println(pair2);


        Main3<String, String> name = new Main3<>();
        name.setKey("name");
        name.setValue("lei");
        System.out.println(name);


        // 自动推断类型（Java 7+）
        var age = Main3.of("Age", 25); // 自动推断为<String, Integer>
        System.out.println(age);


    }
}

interface Name <K,V>{

    K getKey();

    V getValue();
}


